// 统一请求路径前缀在libs/axios.js中修改
import {
  getRequest,
  postRequest,
  deleteRequest,
  managerUrl,
  commonUrl
} from "@/libs/axios";
import axios from "axios";
import { getCookie } from "@/libs/storage.js";

// 获取专栏列表
export const getColumnPage = () => {
  return getRequest(`${managerUrl}/manager/course/category/getCategory`);
}

// 新增、编辑栏目
export const postColumn = (params) => {
  let headers = { "Content-Type": "application/json"}
  return postRequest(`${managerUrl}/manager/course/category/saveOrUpdateCategory`, params, headers);
}

// 删除栏目
export const delColumn = (id) => {
  return deleteRequest(`${managerUrl}/manager/course/category/${id}`);
};

// 获取筛选条件-课程类型列表
export const getColumnType = () => {
  return getRequest(`${managerUrl}/manager/course/category/getCategory`);
}

// 获取课程审核列表
export const postColumnPage = (params) => {
  let headers = { "Content-Type": "application/json"}
  return postRequest(`${managerUrl}/manager/course/courseReviewed/pagelist`, params, headers);
}

// 批量课程审核
export const postDealBat = (params) => {
  let headers = { "Content-Type": "application/json"}
  return postRequest(`${managerUrl}/manager/course/courseReviewed/dealBat`, params, headers);
}

// 置顶
export const postCourseTop = (params) => {
  let headers = { "Content-Type": "application/json"}
  return postRequest(`${managerUrl}/manager/course/courseSeries/setCoursePageTop`, params, headers);
}

// 取消置顶
export const postCancelCourseTop = (params) => {
  let headers = { "Content-Type": "application/json"}
  return postRequest(`${managerUrl}/manager/course/courseSeries/cancelCoursePageTop`, params, headers);
}

// 根据ID获取课程列表
export const getCourseById = (id) => {
  return getRequest(`${managerUrl}/manager/course/course/getCourseByCourseSeriesId/${id}`);
}

// 根据ID获取课程信息
export const getCourseInfoById = (id) => {
  return getRequest(`${managerUrl}/manager/course/courseSeries/${id}`);
}

// 获取课程统计信息
export function getCourseById2(id) {
  return getRequest(`${managerUrl}/manager/course/courseSeries/relevant/${id}`)
}

// 获取课程分页列表
export const postCoursePage = (params) => {
  let headers = { "Content-Type": "application/json"}
  return postRequest(`${managerUrl}/manager/course/courseSeries/byPage`, params, headers);
}

// 获取专家分页列表
export const postExpertPage = (params) => {
  let headers = { "Content-Type": "application/json"}
  return postRequest(`${managerUrl}/manager/expert/expert/list_`, params, headers);
}

// 获取课程评论
export function getCourseInfo(id) {
  return getRequest(`${managerUrl}/manager/course/courseSeriesBaseEvaluate/getEvaluateCount/${id}`);
}

// 课程评论分页数据
export function getCourseContPage(params) {
  let headers = { "Content-Type": "application/json"}
  return postRequest(`${managerUrl}/manager/course/courseSeriesBaseEvaluate/listByPage`, params, headers);
}

// 获取音频流
export const getAudioStream = (audioName, type) => {
  let accessToken = getCookie("accessToken");
  return axios({
    method: `get`,
    url: `${commonUrl}/common/common/source/stream?bucketName=private-o2o&objectName=${audioName}${type}`,
    headers: {
      accessToken: accessToken,
    },
    responseType: `blob`,
  });
};

// 预览word、ppt、pdf
export function solfCourse(data) {
  return postRequest(`${commonUrl}/common/common/upload/oss`, data);
}